package leetcode.code2120;

import leetcode.IDebug;

public class Solution implements IDebug {

	int n;
	char[] orders;
	int len;

	public int[] executeInstructions(int n, int[] startPos, String s) {
		len = s.length();
		int[] ans = new int[len];
		orders = s.toCharArray();
		this.n = n;
		for (int i = 0; i < ans.length; i++) {
			ans[i] = f(startPos[0], startPos[1], i);
		}
		return ans;
	}

	private int f(int x, int y, int index) {
		if (index == len) {
			return 0;
		}
		char cur = this.orders[index];
		if (cur == 'L') {
			y = y - 1;
		} else if (cur == 'R') {
			y = y + 1;
		} else if (cur == 'U') {
			x = x - 1;
		} else {
			x = x + 1;
		}
		if (x < n && x >= 0 && y < n && y >= 0) {
			return this.f(x, y, index + 1) + 1;
		}
		return 0;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
